<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 用户登录表信息
 *
 * @author wutian
 */

namespace Home\Model ;

class UserLoginModel extends \Think\Model
{

    /**
     * 校验密码是否正确
     * @param type $UID
     * @param type $Password
     * @return boolean
     */
    function checkUPassword ( $UID , $Password )
    {
        if ( ! is_numeric ( $UID ) )
        {
            return false ;
        }
        $rs = $this->where ( 'UID = %s' , $UID )->find () ;
        if ( $rs[ 'Password' ] === $Password )
        {
            return true ;
        }
        return false ;
    }

    /**
     * 获取用户身份
     * @param char $UID
     * @return boolean
     */
    function getUserStatusByUID ( $UID )
    {
        if ( ! is_numeric ( $UID ) )
        {
            return false ;
        }
        $rs = $this->where ( 'UID = %s' , $UID )->field ( 'Status' )->find () ;
        return $rs ? $rs[ 'Status' ] : false ;
    }

    /**
     * 用户修改密码
     * @param type $UID
     * @param type $NewPassword
     * @return boolean
     */
    function updateUPassword ( $UID , $NewPassword )
    {
        $map[ 'Password' ] = $NewPassword ;
        $rs                = $this->where ( 'UID = %d' , $UID )->save ( $map ) ;
        if ( false === $rs )
        {
            return false ;
        }
        else
        {
            return true ;
        }
    }

}
